package com.hm.car.api;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.car.api.bean.OfferCallBackVo;
import com.hm.car.service.OfferService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 下午11:33:40 2016年12月13日
 * @version 1.0
 * @describe
 */
@Slf4j
@ResponseBody
@RestController
@RequestMapping("/restful/api/callback")
@CrossOrigin(methods = { RequestMethod.GET, RequestMethod.OPTIONS, RequestMethod.POST, RequestMethod.PUT })
public class ApiCallBackController {

	private static final String SWWAGER_TAG = "第三方接口回调";
	
	@Autowired
	private OfferService offerService;

	@RequestMapping(path = "/offer", method = RequestMethod.POST)
	@ApiOperation(tags = SWWAGER_TAG, value = "报价结果", httpMethod = "POST", notes = "存储报价结果，支付成功，核保结果，承保结果，配送结果，最终状态，主动推送结果给第三方渠道")
	public String offer(
			@ApiParam(required = true, name = "body", value = "报价结果数据结构体") @RequestBody(required = true) OfferCallBackVo callBackVo) {
		log.debug("third-party interface, quotation results callback taskId:{}", callBackVo.getTaskId());
		try {
			log.debug(new Date()+"回调数据："+callBackVo);
			offerService.saveOffer(callBackVo);
			return "200";
		} catch (Exception e) {
			e.printStackTrace();
			log.error("third-party interface, quotation results callback faild "+e.getMessage());
			return "500";
		}
	}
}
